package com.nut.spp.api.client;

import com.nut.spp.common.Result;
import com.nut.spp.jbb.JbbService;
import com.nut.spp.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping("/client/pay")
public class PayController {

    @Autowired
    private PayService payService;

    @Autowired
    private JbbService jbbService;

    /**
     * 预支付订单
     */
    @RequestMapping("prepay")
    public Result<String> prepay(@RequestParam String orderId, HttpServletResponse response) {
        return payService.prepay(orderId, null);
    }

    @RequestMapping("refund")
    public void refund(@RequestParam String payNo, @RequestParam Integer money) {
        jbbService.refund(payNo, money);
    }


    @GetMapping("/pay")
    public String pay(HttpServletResponse response) {

//        PrepayReq req = new PrepayReq();
//        req.setOrderNo(IdUtil.generateSsn());
//        req.setPayMoney(1);
//        req.setPayWay(1);
//        req.setBody("ee2");
//        req.setBizNo("123");

        String orderId = "241021100003";

        Result<String> prepay = payService.prepay(orderId, null);

        if (prepay.isSuccess()) {
            return prepay.getResult().toString();
        }

        return null;


//        PrepayResp resp = jbbService.payPrepay(req);
//        return resp.getQrcodeUrl();

    }

}